#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

#define CHRDEV "/dev/my_device" //字符设备路径

int main(int argc, char **argv){
	int fd;
	char data[1024];
	char recv_data[1024];

	//打开字符设备
	fd = open(CHRDEV, O_RDWR);
	if(fd < 0){
		printf("open failed\n");
		return -1;
	}

	snprintf(data, sizeof(data), "am user data");
	write(fd, data, strlen(data));			//与内核通信，向内核写数据
	printf("send msg: am user data\n");

	//sleep(2);
	read(fd, recv_data, sizeof(recv_data));		//与内核通信，从内核取数据

	printf("recv msg: %s\n", recv_data);		//将从内核读取的数据打印到终端
	return 0;
}
